﻿using System;
using System.Windows;
using System.Windows.Interactivity;

namespace BaseControls
{
    /// <summary>
    /// When user miss click
    /// </summary>
    public class MissHitTrigger : TriggerAction<DependencyObject>
    {
        public int actualCount = 0;
        public MissHitTrigger()
        {
            
        }        
        protected override void OnAttached()
        {
            base.OnAttached();
        }
        /// <summary>
        /// Initiate behavior.
        /// </summary>
        private void InitBehavior()
        {            
            ClockMove clockMove = new ClockMove(Parameter);
            clockMove.Attach(AssociatedObject);           
        }
        protected override void OnDetaching()
        {
            base.OnDetaching();            
        }
        public DependencyProperty CountProperty = DependencyProperty.Register("Count", typeof(int), typeof(MissHitTrigger), null);
        public int Count
        {
            get
            {
                return (int)this.GetValue(CountProperty);
            }
            set
            {
                this.SetValue(CountProperty, value);
            }
        }
        public DependencyProperty BehaviorProperty = DependencyProperty.Register("Behavior", typeof(string), typeof(MissHitTrigger), null);
        public string Behavior
        {
            get
            {                
                return (string)this.GetValue(BehaviorProperty);
            }
            set
            {
                this.SetValue(BehaviorProperty, value);
            }
        }
        public DependencyProperty ParameterProperty = DependencyProperty.Register("Parameter", typeof(string), typeof(MissHitTrigger), null);
        public string Parameter
        {
            get
            {
                return (string)this.GetValue(ParameterProperty);
            }
            set
            {
                this.SetValue(ParameterProperty, value);
            }
        }

        protected override void Invoke(object parameter)
        {
            if (actualCount == Count)
            {
                actualCount = 0;//restart                
                InitBehavior();
            }
            else
                actualCount++;
        }
    }
}